Re: [GENERAL] Another one! :) How to convert char(1) to boolean without re-exporting tables. - Mailing list pgsql-general

From Herouth Maoz
Subject Re: [GENERAL] Another one! :) How to convert char(1) to boolean without re-exporting tables.
Date
Msg-id l03110700b2ca56ffa369@[147.233.159.109]
Whole thread Raw
In response to Another one! :) How to convert char(1) to boolean without re-exporting tables.  (Valerio Santinelli <tanis@mediacom.it>)
List pgsql-general
At 16:58 +0200 on 19/1/99, Valerio Santinelli wrote:


> char(1) won't let me insert into it the values contained in the old
> table seeing they're not of the same type.

Why not? It all depends on how you populate the new table. You do that
usually with a SELECT statement. A select statement like

SELECT field_1, field_2, ( char_field = '1' ), field 4, field5...

gives you a boolean expression - is the char_field equal to '1' at the
current row?

Some versions of Postgres crash when given a boolean expression on the
select target list. In that case you can define it as a function

CREATE FUNCTION is_one( bpchar ) RETURNS bool
AS 'SELECT $1 = ''1'''
LANGUAGUE 'sql';

And then do the select as

SELECT field_1, field_2, is_one( char_field), field4, field5....

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma



pgsql-general by date:

Previous
From: Valerio Santinelli
Date:
Subject: Another one! :) How to convert char(1) to boolean without re-exporting tables.
Next
From: "Jose' Soares"
Date:
Subject: Re: [GENERAL] How to increment by hand a sequence number.